var express = require('express');
var router = express.Router();
var passport = require('passport');

var user = require('../controller/user');

// router.get('/',passport.authenticate('local',{
//       successRedirect: '/',
//       failureRedirect: '/',
//       failureFlash : true
//     }), function(req, res, next) {
//     res.render('index', { title: '谷城-个人博客' });
// });

router.get('/',function(req, res, next) {

  var app = req.app;
  res.render = function(view, locals,cb){
    app.render(view, locals,function(err,html){
      if(typeof cb !== undefined){
        return cb(err, html);
      }  
    });
  };

  res.render('index',{title:"首页",curr:"index" },function(err,html){
      res.send(html);
  });


});

router.get('/archives/:id',function(req, res, next) {
  res.render('archives',{title:"这是一个帖子内容页面"});
});
router.get('/archives',function(req, res, next) {
  res.render('archives_list',{title:"这是帖子列表",curr:"archives"});
});
router.get('/about',function(req,res,next){
  res.render('about',{title:"关于我",curr:"about"});
});

// router.get('/user/regist', function(req, res, next) {
//   res.render("user/regist");
// });

// router.get('/user/login', function(req, res, next) {
//   res.render("user/login");
// });

// router.post('/user/login', user.userLogin);

// function isLoggedIn(req, res, next) {
//   if (req.isAuthenticated()){
//       return next()
//   }
//   res.redirect('/');
// }

module.exports = router;
